<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- /fasttmp/mkdist-qt-4.3.5-1211793125/qtopia-core-opensource-src-4.3.5/src/gui/kernel/qevent.cpp -->
<head>
  <title>Qt 4.3: QInputMethodEvent Class Reference</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
<td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></table><h1 align="center">QInputMethodEvent Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1>
<p>The QInputMethodEvent class provides parameters for input method events. <a href="#details">More...</a></p>
<pre> #include &lt;QInputMethodEvent&gt;</pre><p>Inherits <a href="qevent.html">QEvent</a>.</p>
<ul>
<li><a href="qinputmethodevent-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="public-types"></a>
<h3>Public Types</h3>
<ul>
<li><div class="fn"/>class <b><a href="qinputmethodevent-attribute.html">Attribute</a></b></li>
<li><div class="fn"/>enum <b><a href="qinputmethodevent.html#AttributeType-enum">AttributeType</a></b> { TextFormat, Cursor, Language, Ruby }</li>
</ul>
<a name="public-functions"></a>
<h3>Public Functions</h3>
<ul>
<li><div class="fn"/><b><a href="qinputmethodevent.html#QInputMethodEvent">QInputMethodEvent</a></b> ()</li>
<li><div class="fn"/><b><a href="qinputmethodevent.html#QInputMethodEvent-2">QInputMethodEvent</a></b> ( const QString &amp; <i>preeditText</i>, const QList&lt;Attribute&gt; &amp; <i>attributes</i> )</li>
<li><div class="fn"/><b><a href="qinputmethodevent.html#QInputMethodEvent-3">QInputMethodEvent</a></b> ( const QInputMethodEvent &amp; <i>other</i> )</li>
<li><div class="fn"/>const QList&lt;Attribute&gt; &amp; <b><a href="qinputmethodevent.html#attributes">attributes</a></b> () const</li>
<li><div class="fn"/>const QString &amp; <b><a href="qinputmethodevent.html#commitString">commitString</a></b> () const</li>
<li><div class="fn"/>const QString &amp; <b><a href="qinputmethodevent.html#preeditString">preeditString</a></b> () const</li>
<li><div class="fn"/>int <b><a href="qinputmethodevent.html#replacementLength">replacementLength</a></b> () const</li>
<li><div class="fn"/>int <b><a href="qinputmethodevent.html#replacementStart">replacementStart</a></b> () const</li>
<li><div class="fn"/>void <b><a href="qinputmethodevent.html#setCommitString">setCommitString</a></b> ( const QString &amp; <i>commitString</i>, int <i>replaceFrom</i> = 0, int <i>replaceLength</i> = 0 )</li>
</ul>
<ul>
<li><div class="fn"/>6 public functions inherited from <a href="qevent.html#public-functions">QEvent</a></li>
</ul>
<h3>Additional Inherited Members</h3>
<ul>
<li><div class="fn"/>1 property inherited from <a href="qevent.html#properties">QEvent</a></li>
</ul>
<a name="details"></a>
<hr />
<h2>Detailed Description</h2>
<p>The QInputMethodEvent class provides parameters for input method events.</p>
<p>Input method events are sent to widgets when an input method is used to enter text into a widget. Input methods are widely used to enter text for languages with non-Latin alphabets.</p>
<p>Note that when creating custom text editing widgets, the <a href="qt.html#WidgetAttribute-enum">Qt::WA_InputMethodEnabled</a> window attribute must be set explicitly (using the <a href="qwidget.html#setAttribute">QWidget::setAttribute</a>() function) in order to receive input method events.</p>
<p>The events are of interest to authors of keyboard entry widgets who want to be able to correctly handle languages with complex character input. Text input in such languages is usually a three step process:</p>
<ol type="1">
<li><b>Starting to Compose</b><p>When the user presses the first key on a keyboard, an input context is created. This input context will contain a string of the typed characters.</p>
</li>
<li><b>Composing</b><p>With every new key pressed, the input method will try to create a matching string for the text typed so far called preedit string. While the input context is active, the user can only move the cursor inside the string belonging to this input context.</p>
</li>
<li><b>Completing</b><p>At some point, the user will activate a user interface component (perhaps using a particular key) where they can choose from a number of strings matching the text they have typed so far. The user can either confirm their choice cancel the input; in either case the input context will be closed.</p>
</li>
</ol>
<p>QInputMethodEvent models these three stages, and transfers the information needed to correctly render the intermediate result. A QInputMethodEvent has two main parameters: <a href="qinputmethodevent.html#preeditString">preeditString</a>() and <a href="qinputmethodevent.html#commitString">commitString</a>(). The <a href="qinputmethodevent.html#preeditString">preeditString</a>() parameter gives the currently active preedit string. The <a href="qinputmethodevent.html#commitString">commitString</a>() parameter gives a text that should get added to (or replace parts of) the text of the editor widget. It usually is a result of the input operations and has to be inserted to the widgets text directly before the preedit string.</p>
<p>If the <a href="qinputmethodevent.html#commitString">commitString</a>() should replace parts of the of the text in the editor, <a href="qinputmethodevent.html#replacementLength">replacementLength</a>() will contain the number of characters to be replaced. <a href="qinputmethodevent.html#replacementStart">replacementStart</a>() contains the position at which characters are to be replaced relative from the start of the preedit string.</p>
<p>A number of attributes control the visual appearance of the preedit string (the visual appearance of text outside the preedit string is controlled by the widget only). The <a href="qinputmethodevent.html#AttributeType-enum">AttributeType</a> enum describes the different attributes that can be set.</p>
<p>A class implementing <a href="qwidget.html#inputMethodEvent">QWidget::inputMethodEvent</a>() should at least understand and honor the <a href="qinputmethodevent.html#AttributeType-enum">TextFormat</a> and <a href="qinputmethodevent.html#AttributeType-enum">Cursor</a> attributes.</p>
<p>Since input methods need to be able to query certain properties from the widget, the widget must also implement <a href="qwidget.html#inputMethodQuery">QWidget::inputMethodQuery</a>().</p>
<p>When receiving an input method event, the text widget has to performs the following steps:</p>
<ol type="1">
<li>If the widget has selected text, the selected text should get removed.</li>
<li>Remove the text starting at <a href="qinputmethodevent.html#replacementStart">replacementStart</a>() with length <a href="qinputmethodevent.html#replacementLength">replacementLength</a>() and replace it by the <a href="qinputmethodevent.html#commitString">commitString</a>(). If <a href="qinputmethodevent.html#replacementLength">replacementLength</a>() is 0, <a href="qinputmethodevent.html#replacementStart">replacementStart</a>() gives the insertion position for the <a href="qinputmethodevent.html#commitString">commitString</a>().<p>When doing replacement the area of the preedit string is ignored, thus a replacement starting at -1 with a length of 2 will remove the last character before the preedit string and the first character afterwards, and insert the commit string directly before the preedit string.</p>
<p>If the widget implements undo/redo, this operation gets added to the undo stack.</p>
</li>
<li>If there is no current preedit string, insert the <a href="qinputmethodevent.html#preeditString">preeditString</a>() at the current cursor position; otherwise replace the previous preeditString with the one received from this event.<p>If the widget implements undo/redo, the <a href="qinputmethodevent.html#preeditString">preeditString</a>() should not influence the undo/redo stack in any way.</p>
<p>The widget should examine the list of attributes to apply to the preedit string. It has to understand at least the <a href="qinputmethodevent.html#AttributeType-enum">TextFormat</a> and Cursor attributes and render them as specified.</p>
</li>
</ol>
<p>See also <a href="qinputcontext.html">QInputContext</a>.</p>
<hr />
<h2>Member Type Documentation</h2>
<h3 class="fn"><a name="AttributeType-enum"></a>enum QInputMethodEvent::AttributeType</h3>
<p><table border="1" cellpadding="2" cellspacing="1" width="100%">
<tr><th width="25%">Constant</th><th width="15%">Value</th><th width="60%">Description</th></tr>
<tr><td valign="top"><tt>QInputMethodEvent::TextFormat</tt></td><td align="center" valign="top"><tt>0</tt></td><td valign="top">A <a href="qtextcharformat.html">QTextCharFormat</a> for the part of the preedit string specified by start and length. value contains a <a href="qvariant.html">QVariant</a> of type <a href="qtextformat.html">QTextFormat</a> specifying rendering of this part of the preedit string. There should be at most one format for every part of the preedit string. If several are specified for any character in the string the behaviour is undefined. A conforming implementation has to at least honor the backgroundColor, textColor and fontUnderline properties of the format.</td></tr>
<tr><td valign="top"><tt>QInputMethodEvent::Cursor</tt></td><td align="center" valign="top"><tt>1</tt></td><td valign="top">If set, a cursor should be shown inside the preedit string at position start. The length variable determines whether the cursor is visible or not. If the length is 0 the cursor is invisible. If value is a <a href="qvariant.html">QVariant</a> of type <a href="qcolor.html">QColor</a> this color will be used for rendering the cursor, otherwise the color of the surrounding text will be used. There should be at most one Cursor attribute per event. If several are specified the behaviour is undefined.</td></tr>
<tr><td valign="top"><tt>QInputMethodEvent::Language</tt></td><td align="center" valign="top"><tt>2</tt></td><td valign="top">The variant contains a <a href="qlocale.html">QLocale</a> object specifying the language of a certain part of the preedit string. There should be at most one language set for every part of the preedit string. If several are specified for any character in the string the behaviour is undefined.</td></tr>
<tr><td valign="top"><tt>QInputMethodEvent::Ruby</tt></td><td align="center" valign="top"><tt>3</tt></td><td valign="top">The ruby text for a part of the preedit string. There should be at most one ruby text set for every part of the preedit string. If several are specified for any character in the string the behaviour is undefined.</td></tr>
</table></p>
<p>See also <a href="qinputmethodevent-attribute.html">Attribute</a>.</p>
<hr />
<h2>Member Function Documentation</h2>
<h3 class="fn"><a name="QInputMethodEvent"></a>QInputMethodEvent::QInputMethodEvent ()</h3>
<p>Constructs an event of type <a href="qevent.html#Type-enum">QEvent::InputMethod</a>. The <a href="qinputmethodevent.html#attributes">attributes</a>(), <a href="qinputmethodevent.html#preeditString">preeditString</a>(), <a href="qinputmethodevent.html#commitString">commitString</a>(), <a href="qinputmethodevent.html#replacementStart">replacementStart</a>(), and <a href="qinputmethodevent.html#replacementLength">replacementLength</a>() are initialized to default values.</p>
<p>See also <a href="qinputmethodevent.html#setCommitString">setCommitString</a>().</p>
<h3 class="fn"><a name="QInputMethodEvent-2"></a>QInputMethodEvent::QInputMethodEvent ( const <a href="qstring.html">QString</a> &amp; <i>preeditText</i>, const <a href="qlist.html">QList</a>&lt;<a href="qinputmethodevent-attribute.html">Attribute</a>&gt; &amp; <i>attributes</i> )</h3>
<p>Construcs an event of type <a href="qevent.html#Type-enum">QEvent::InputMethod</a>. The preedit text is set to <i>preeditText</i>, the attributes to <i>attributes</i>.</p>
<p>The <a href="qinputmethodevent.html#commitString">commitString</a>(), <a href="qinputmethodevent.html#replacementStart">replacementStart</a>(), and <a href="qinputmethodevent.html#replacementLength">replacementLength</a>() values can be set using <a href="qinputmethodevent.html#setCommitString">setCommitString</a>().</p>
<p>See also <a href="qinputmethodevent.html#preeditString">preeditString</a>() and <a href="qinputmethodevent.html#attributes">attributes</a>().</p>
<h3 class="fn"><a name="QInputMethodEvent-3"></a>QInputMethodEvent::QInputMethodEvent ( const QInputMethodEvent &amp; <i>other</i> )</h3>
<p>Constructs a copy of <i>other</i>.</p>
<h3 class="fn"><a name="attributes"></a>const <a href="qlist.html">QList</a>&lt;<a href="qinputmethodevent-attribute.html">Attribute</a>&gt; &amp; QInputMethodEvent::attributes () const</h3>
<p>Returns the list of attributes passed to the <a href="qinputmethodevent.html">QInputMethodEvent</a> constructor. The attributes control the visual appearance of the preedit string (the visual appearance of text outside the preedit string is controlled by the widget only).</p>
<p>See also <a href="qinputmethodevent.html#preeditString">preeditString</a>() and <a href="qinputmethodevent-attribute.html">Attribute</a>.</p>
<h3 class="fn"><a name="commitString"></a>const <a href="qstring.html">QString</a> &amp; QInputMethodEvent::commitString () const</h3>
<p>Returns the text that should get added to (or replace parts of) the text of the editor widget. It usually is a result of the input operations and has to be inserted to the widgets text directly before the preedit string.</p>
<p>See also <a href="qinputmethodevent.html#setCommitString">setCommitString</a>(), <a href="qinputmethodevent.html#preeditString">preeditString</a>(), <a href="qinputmethodevent.html#replacementStart">replacementStart</a>(), and <a href="qinputmethodevent.html#replacementLength">replacementLength</a>().</p>
<h3 class="fn"><a name="preeditString"></a>const <a href="qstring.html">QString</a> &amp; QInputMethodEvent::preeditString () const</h3>
<p>Returns the preedit text, i.e&#x2e; the text before the user started editing it.</p>
<p>See also <a href="qinputmethodevent.html#commitString">commitString</a>() and <a href="qinputmethodevent.html#attributes">attributes</a>().</p>
<h3 class="fn"><a name="replacementLength"></a>int QInputMethodEvent::replacementLength () const</h3>
<p>Returns the number of characters to be replaced in the preedit string.</p>
<p>See also <a href="qinputmethodevent.html#replacementStart">replacementStart</a>() and <a href="qinputmethodevent.html#setCommitString">setCommitString</a>().</p>
<h3 class="fn"><a name="replacementStart"></a>int QInputMethodEvent::replacementStart () const</h3>
<p>Returns the position at which characters are to be replaced relative from the start of the preedit string.</p>
<p>See also <a href="qinputmethodevent.html#replacementLength">replacementLength</a>() and <a href="qinputmethodevent.html#setCommitString">setCommitString</a>().</p>
<h3 class="fn"><a name="setCommitString"></a>void QInputMethodEvent::setCommitString ( const <a href="qstring.html">QString</a> &amp; <i>commitString</i>, int <i>replaceFrom</i> = 0, int <i>replaceLength</i> = 0 )</h3>
<p>Sets the commit string to <i>commitString</i>.</p>
<p>The commit string is the text that should get added to (or replace parts of) the text of the editor widget. It usually is a result of the input operations and has to be inserted to the widgets text directly before the preedit string.</p>
<p>If the commit string should replace parts of the of the text in the editor, <i>replaceLength</i> specifies the number of characters to be replaced. <i>replaceFrom</i> specifies the position at which characters are to be replaced relative from the start of the preedit string.</p>
<p>See also <a href="qinputmethodevent.html#commitString">commitString</a>(), <a href="qinputmethodevent.html#replacementStart">replacementStart</a>(), and <a href="qinputmethodevent.html#replacementLength">replacementLength</a>().</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="30%">Copyright &copy; 2008 <a href="trolltech.html">Trolltech</a></td>
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="30%" align="right"><div align="right">Qt 4.3.5</div></td>
</tr></table></div></address></body>
</html>
